/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sgt.supermarket.hibernatedao;

import org.hibernate.Session;
import org.hibernate.criterion.Expression;
import sgt.supermarket.entity.Category;

/**
 *
 * @author Administrator
 */
public class HibernateCategoryDAO extends HibernateGenericDAO<Category, Long> {

    public HibernateCategoryDAO(Session session) {
        super(session);
    }

    public Category getByName(String name) {
        return (Category) getSession().createCriteria(Category.class).add(Expression.eq("name", name)).uniqueResult();
    }

    public Category getRoot(){
        return (Category) getSession().createCriteria(Category.class).add(Expression.isNull("parent")).uniqueResult();
    }
}
